Conversation
dardecena
left a comment
There was a problem hiding this comment.
Great effort...almost there. Please try exercise 3 and 5-q4 again.
I added some additional comments. Please reflect on them and keep them in mind for future assignments.
| function doubleEvenNumbers(numbers) { | ||
| // TODO rewrite the function body using `map` and `filter`. | ||
| return numbers.filter(n => n % 2 === 0).map(n => n * 2); | ||
| } | ||
| module.exports = doubleEvenNumbers; | ||
| // ! Unit test (using Jest) | ||
| describe('js-wk3-ex1-doubleEvenNumbers', () => { | ||
| test('doubleEvenNumbers should take the even numbers and double them', () => { | ||
| const actual = doubleEvenNumbers([1, 2, 3, 4]); | ||
| const expected = [4, 8]; | ||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
This seems to be a duplicate file. In the future, please edit assignment and remove redundant code/files before submitting.
| } | ||
| } | ||
| return newNumbers; | ||
| return numbers.filter(n => n % 2 === 0).map(n => n * 2); |
There was a problem hiding this comment.
Great job using the filter() and map() method 😄
| const eurosFormatter = new Intl.NumberFormat('nl-NL', { | ||
| style: 'currency', | ||
| currency: 'EUR', | ||
| }); |
There was a problem hiding this comment.
Note: This returns a slightly different format than the expected value on the unit test (eg. '€NBSP187,50')
| function computeEarnings(tasks, hourlyRate) { | ||
| const totalMinutes = Array.isArray(tasks) | ||
| ? tasks.reduce((sum, t) => sum + (Number(t?.duration) || 0), 0) | ||
| : 0; | ||
|
|
||
| const totalHours = totalMinutes / 60; | ||
| const earnings = totalHours * Number(hourlyRate || 0); | ||
|
|
||
| return eurosFormatter.format(earnings); | ||
| } |
There was a problem hiding this comment.
Good job using the reduce() method.
Challenge: How would you rewrite this function if you were to also apply the map() function, and return the required format without using the eurosFormatter() function?
Note: The tests were removed from the file. Please restore them.
| @@ -0,0 +1,36 @@ | |||
| const sanitizeFruitBasket = require('./ex3-lemonAllergy'); | |||
There was a problem hiding this comment.
The function sanitizeFruitBasket() seems to be incomplete. Could you try again?
| // prettier-ignore | ||
| // eslint-disable-next-line no-unused-vars | ||
| const quiz = { | ||
| q1: { answer: 'b' }, |
| // eslint-disable-next-line no-unused-vars | ||
| const quiz = { | ||
| q1: { answer: 'b' }, | ||
| q2: { answer: 'c' }, |
| const quiz = { | ||
| q1: { answer: 'b' }, | ||
| q2: { answer: 'c' }, | ||
| q3: { answer: 'a' }, |
| q1: { answer: 'b' }, | ||
| q2: { answer: 'c' }, | ||
| q3: { answer: 'a' }, | ||
| q4: { answer: 'b' }, |
| q2: { answer: 'c' }, | ||
| q3: { answer: 'a' }, | ||
| q4: { answer: 'b' }, | ||
| q5: { answer: 'c' }, |
No description provided.